package com.itheima.config;


import com.itheima.constant.HttpStatus;
import com.itheima.exception.UserException;
import com.itheima.vo.domain.AjaxResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * 全局异常处理类
 */
@RestControllerAdvice
@Slf4j
public class GlobalExceptionHandler {

/**
     * 处理普通异常
     * @param e 登录异常对象
     * @return  错误信息
     */

    @ExceptionHandler(Exception.class)
    public AjaxResult handleException(Exception e)
    {
        log.error(e.getMessage());
        return AjaxResult.error(HttpStatus.ERROR, "服务器连接超时");
    }

    /**
     * 处理登录异常
     * @param e 登录异常对象
     * @return  错误信息
     */
    @ExceptionHandler(UserException.class)
    public AjaxResult handleUserException(UserException e)
    {
        log.error(e.getMessage());
        return AjaxResult.error(e.getHttpCode(),e.getMessage());
    }


}
